/**
 * Inventory.java
 */
package edu.gatech.startrader.trade;

import java.util.HashMap;
import java.util.Map;

import edu.gatech.startrader.universe.Planet;

/**
 * Inventory Class
 * This class represents an inventory
 * @author Team Bamf (Team 30)
 * @version : 1.0
 */
public class Inventory {
	/**
	 * amount HashMap
	 */
	protected Map<TradeGood, Integer> amount;
	
	/**
	 * Inventory Constructor
	 * Creates an Inventory and sets the default prices and default amounts. 
	 */
	public Inventory() {
		amount = new HashMap<TradeGood, Integer>(); //sets the amount of each good
		for(int i = 0; i < TradeGood.values().length; i++) {
			amount.put(TradeGood.values()[i], 0);
		}
	}

	/**
	 * getAmount method
	 * Gets the amount of a TradeGood in the Inventory.
	 * @param tradeGood TradeGood to check
	 * @return the amount of TradeGood in the Inventory
	 */
	public int getAmount(TradeGood tradeGood) {
		return amount.get(tradeGood);
	}
	
	/**
	 * add Method
	 * This method adds a resource and it's amount
	 * @param type the kind of resource to be added
	 * @param number the number of resources to be added
	 */
	public void add(TradeGood type, int number) {
		setAmount(type, amount.get(type) + number);
	}
	
	/**
	 * remove Method
	 * This method removes a specified amount of a resource
	 * @param type the type of resource to  be removed
	 * @param number the number of resources to be removed
	 */
	public void remove(TradeGood type, int number)  {
		if(number > amount.get(type)) {
			throw new IllegalArgumentException(
					"Cannot remove more " + 
					type.toString() + 
					" than the Inventory has");
		}
		setAmount(type, amount.get(type) - number);
	}
	
	/**
	 * setAmount method
	 * Sets the amount of a TradeGood in the Inventory
	 * @param type the TradeGood type
	 * @param number the number of resources to be set to
	 */
	private void setAmount(TradeGood type, int number) {
		amount.put(type, number);
	}
	
	/**
	 * generateAmount method
	 * Generate amount depending on Planet
	 * @param planet the selected Planet
	 */
	public void generateAmount(Planet planet) {
		final TradeGood[] goods = TradeGood.values();
		for(int i = 0; i < goods.length; i++){
			setAmount(goods[i], goods[i].determineAmount(planet));
		}
	}
}
